#ifndef __SMI__
#define __SMI__
#include "Type_Define.h"
#include "IO_LINK_Global_Param.h"

typedef struct 
{
   uint8_t ClientID;
   uint8_t Port;
   uint16_t ExpArgBlockID;
   uint8_t ArgBlockLength;
   void * ArgBlock;
     
}SMI_Object_TYPE;



//***************返回Argblock*从设备到网关***************
 typedef struct {
    uint16_t ArgBlockID;
    uint16_t VendorID;
    uint8_t MasterType;
    uint8_t Features_1;
    uint8_t Features_2;
    uint8_t MaxNumberOfPorts;
    uint8_t PortTypes[PORT_NUM];
  }MasterIdent_TYPE;


  typedef struct  //子结构体
  {
       uint8_t EventQualifier;
       uint16_t EventCode;
  }DiagEntryTYPE;
  
  typedef struct {
    uint16_t ArgBlockID;
    uint8_t PortStatusInfo;
    uint8_t PortQualityInfo;
    uint8_t RevisionID;
    uint8_t TransmissionRete;
    uint8_t MasterCycleTime;
    uint8_t InputDataLength;
    uint8_t OutputDataLength;
    uint16_t VendorID;
    uint32_t DeviceID;
    uint8_t NumberOfDiags;
    DiagEntryTYPE DiagEntry[0];
  }PortStatusList_TYPE;



typedef struct  
 {  uint16_t ArgBlockID;
    uint8_t PQI;
    uint8_t InputDataLength;
    uint8_t PDI[0];
     
 }PDIn_TYPE;

 typedef struct   
 {
     uint16_t ArgBlockID;
     uint8_t PDI0;
 }PDInQ_TYPE;

typedef struct 
{
   uint16_t ArgBlockID;
   uint8_t EventQualifer;
   uint16_t EventCode;
}DeviceEvent_TYPE;

typedef struct{
   uint16_t ArgBlockID;
   uint8_t EventQualifer;
   uint16_t EventCode;
} PortEvent_TYPE;

typedef struct {
   uint16_t ArgBlockID;
}VoidBlock_TYPE;

typedef struct 
{
     uint16_t ArgBlockID;
     uint16_t ExpArgBlockID;
     uint8_t ErrorCode;
     uint8_t AdditionalCode;
}JobError_TYPE;

//****************输入Argblock,从网关到设备
  typedef struct {
    uint16_t ArgBlockID;
    uint8_t PortMode;
    uint8_t Validation_and_Backup;
    uint8_t IQ_behavior;
    uint8_t PortCycleTime;
    uint16_t VendorID;
    uint32_t DeviceID;
  }PortConfigList_TYPE;

 typedef struct {
 
    uint16_t Entry_Index;
    uint8_t Entry_Subindex;
 
 }IndexList_TYPE;

 typedef struct {
   uint16_t ArgBlockID;
   uint8_t PortPowerMode;
   uint16_t PowerOffTime;
 }PortPowerOffOn_TYPE;

typedef struct {
   uint16_t ArgBlockID;
   uint8_t OE;
   uint8_t OutputDataLength;
   uint8_t PDO[0];
  }PDOut_TYPE;
 
 typedef struct 
 {
   uint16_t ArgBlockID;
   uint8_t PDO0;
 }PDOutIQ_TYPE;
 
 

  //************输入输出Argblock*********/
typedef struct {  //子结构体
    uint16_t ISDU_Index;
    uint8_t  ISDU_Subindex;
    uint8_t  ISDU_Length;
    uint8_t  ISDU_Data[0];
}DS_object_TYPE;
  
typedef   struct {
     uint16_t ArgBlockID;
     struct Header{
       uint32_t Parameter_Checksum;
       uint16_t VendorID;
       uint32_t DeviceID;
       uint16_t FunctionID;
}DS_Data_TYPE;
     DS_object_TYPE   Ds_object[0] ;  

  };


typedef struct {
    uint16_t ArgBlockID;
    uint16_t Index;
    uint8_t Subindex;
    uint8_t Data[0] ;
  }On_request_Data_TYPE;

typedef struct { //子结构体,见Table E.7
   uint16_t Object_Index;
   uint8_t Object_SubIndex;
   uint8_t Object_Length;
   uint8_t Object_Length_ISUD_error; 
   uint8_t Object_Data[0];
}Paramter_struct_TYPE;

typedef struct 
  {  uint16_t ArgBlockID;
     Paramter_struct_TYPE Object[0];
     
  }DeviceParBatch_TYPE;

typedef struct 
{
    uint16_t ArgBlockID;
    uint8_t PQI;
    uint8_t OE;
    uint8_t InputDataLength;
    uint8_t OutputDataLength;
    uint8_t PDOI[0]; //或者是PDIn 或者是PDOut

}PDInOut_TYPE;



  
 
 


//保存SMI接口配置的ConfigList
extern PortConfigList_TYPE SMI_PortConfigList[PORT_NUM]; 
 


//插入SMI_Object到输入OUT FIFO,发向上游网关,由IO-LINK协议调用
BOOL Insert_SMI_Object_To_Result_FIFO(uint8_t ClinetID,uint8_t Port ,uint8_t ArgBlockLength,void * ArgBlock);
 

#endif
